﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Caching;

namespace Lync.Widget.Library.Caching
{
    public class CacheManager : ICacheManager
    {
        public T Get<T>(string cacheKey) where T : class
        {
            return HttpRuntime.Cache.Get(cacheKey) as T;
        }

        public IList<T> GetList<T>(string cacheKey)
        {
            return HttpRuntime.Cache.Get(cacheKey) as IList<T>;
        }

        public void Add<T>(string cacheKey, T obj, int cacheMinutes) where T : class
        {
            if (obj == null || cacheMinutes == 0)
                return;

            HttpRuntime.Cache.Insert(cacheKey, obj, null, DateTime.Now.AddMinutes(cacheMinutes), Cache.NoSlidingExpiration);
        }
    }
}